//
// Created by antler on 2018/12/10.
//

#ifndef LUA_TOLUA_HELPER_H
#define LUA_TOLUA_HELPER_H

#include <string>

#include "tolua++.h"

#define TOLUAHELPER_CLASS_VARIABLE(L, var_name) \
  tolua_variable(L, #var_name, get_##var_name , set_##var_name);

#define TOLUAHELPER_CLASS_CONST_VARIABLE(L, var_name) \
  tolua_variable(L, #var_name, get_##var_name , nullptr);

#define TOLUAHELPER_CLASS_CONST_VARIABLE_NS(L, NS, var_name) \
  tolua_variable(L, #var_name, get_##NS##_##var_name , nullptr);

TOLUA_API void toluahelper_setfunc(lua_State *L, const luaL_Reg *l);

TOLUA_API void *toluahelper_tousertype(lua_State *L, int narg, const char *type, void *def,
                                       tolua_Error *err = nullptr);

TOLUA_API void toluahelper_json2table(lua_State *L, const std::string &json);

TOLUA_API std::string toluahelper_table2json(lua_State *L, int idx);

TOLUA_API void toluahelper_keyvalue2table(lua_State *L, const std::string &key, bool value);

TOLUA_API void toluahelper_keyvalue2table(lua_State *L, const std::string &key, double value);

TOLUA_API void
toluahelper_keyvalue2table(lua_State *L, const std::string &key, const std::string &value);

#define TOLUAHELPER_REFID_FUNCTION_MAPPING "toluahelper_refid_function_mapping"

TOLUA_API void toluahelper_open(lua_State *L);

TOLUA_API int toluahelper_ref_function(lua_State *L, int lo);

TOLUA_API void toluahelper_get_function_by_refid(lua_State *L, int refid);

TOLUA_API void toluahelper_remove_function_by_refid(lua_State *L, int refid);

#endif //LUA_TOLUA_HELPER_H
